<?php ;

require mnminclude.'class.BasePage.inc';
require mnminclude.'class.DbUpdater.inc';

class AdminDbUpdatePage extends BasePage {
    public $center = 'admin_templates/dbupdate';
    public $title = 'PLIGG_Visual_Header_AdminPanel';
    public $needAdmin = true;

    private $dbu;

    public function process() {
        parent::process();

        if (! $this->isAdmin()) return;

        $dbu = $this->dbu = new DbUpdater();

        if (isset($_GET['action'])) {
            $this->act($_GET['action']);
        }

        $smarty = $this->smarty;
        $current = $dbu->current();
        $expected = $dbu->expected();
        $smarty->assign('current', $current);
        $smarty->assign('expected', $expected);

        $selfUrl = $this->selfUrl();
        if ($current != $expected) {
            $smarty->assign('updateUrl', $selfUrl . '?action=update');
        }
        $smarty->assign('saveUrl', $selfUrl . '?action=save');
        $smarty->assign('loadUrl', $selfUrl . '?action=load');
    }

    public function render() {
        parent::render();
    }

    private function act($action) {
        // xxx stub
        switch ($action) {
        default:
            $this->error('unknown action ' . $action);
            return;
        }
    }
}
